<?php
namespace Kuoqi\Api\Weixin\Mp;
use Kuoqi\Api\Weixin\Tools;
use Kuoqi\Api\Weixin\Config;
/**
 * 微信粉丝模块的基础接口等
 * Class Fans
 * @package Kuoqi\Api\Weixin\Mp
 */
class Scene{
    //https://developers.weixin.qq.com/doc/offiaccount/Account_Management/Generating_a_Parametric_QR_Code.html
    //二维码获取链接地址
    static $url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=%s';//post

    static $url_ticket = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s';


    /**
     * 用户临时授权 QR_SCENE 使用数字场景的临时二维码
     * vbase
     * @param string $openid
     * @param string $auth_token
     * @return array
     * 二维码类型，QR_SCENE为临时的整型参数值，QR_STR_SCENE为临时的字符串参数值，QR_LIMIT_SCENE为永久的整型参数值，QR_LIMIT_STR_SCENE为永久的字符串参数值
     */
    public function getQrScene($sceneId,$expireSec = '604800'){
        $url = sprintf(self::$url,
            Config::getAccessToken()
        );
        $data = array(
            'expire_seconds'=>$expireSec,
            'action_name'=>'QR_SCENE',
            'action_info'=>array(
                'scene'=>array(
                    'scene_id'=>$sceneId,
                )
            ),
        );
        $response = new response(tools::sendTo($url,'json',$data));
        return $response->toArray();
    }

    /**
     * 获取字符串的临时二维码
     * vbase
     * @return array
     */
    public function getQrStrScene($sceneStr,$expireSec = '604800'){
        $url = sprintf(self::$url,
            Config::getAccessToken()
        );
        $data = array(
            'expire_seconds'=>$expireSec,
            'action_name'=>'QR_STR_SCENE',
            'action_info'=>array(
                'scene'=>array(
                    'scene_str'=>$sceneStr,
                )
            ),
        );
        $response = new response(tools::sendTo($url,'json',$data));
        return $response->toArray();
    }

    /**
     * 获取数字版本的永久二维码
     * vbase
     * @return array
     */
    public function getQrLimitScene($sceneId){
        $url = sprintf(self::$url,
            Config::getAccessToken()
        );
        $data = array(
            'action_name'=>'QR_LIMIT_SCENE',
            'action_info'=>array(
                'scene'=>array(
                    'scene_id'=>$sceneId,
                )
            ),
        );
        $response = new response(tools::sendTo($url,'json',$data));
        return $response->toArray();
    }

    /**
     * 获取字符串版本的永久的场景二维码
     * vbase
     * @return array
     */
    public function getQrLimitstrScene($sceneStr){
        $url = sprintf(self::$url,
            Config::getAccessToken()
        );
        $data = array(
            'action_name'=>'QR_LIMIT_STR_SCENE',
            'action_info'=>array(
                'scene'=>array(
                    'scene_str'=>$sceneStr,
                )
            ),
        );
        $response = new response(tools::sendTo($url,'json',$data));
        return $response->toArray();
    }

}